home *** CD-ROM | disk | FTP | other *** search
- /*
- * rg - start a gem program under mint/tcsh
- *
- * compile -mshort with mint libs
- */
-
- static char *rcsid = "$Id: rg.c,v 1.0 1992/06/15 02:14:30 rosenkra Exp $";
-
- /*
- * $Log: rg.c,v $
- * Revision 1.0 1992/06/15 02:14:30 rosenkra
- * Initial revision
- *
- */
-
- #include <stdio.h>
- #include <string.h> /* for strcpy(), strcat() */
- #include <stdlib.h> /* for exit() */
- #include <unistd.h> /* for sleep() */
- #ifdef NEW_SCREEN
- #define __NO_MFDB__ /* avoid conflicts in gemfast.h and linea.h */
- #endif
- #include <gemdefs.h>
- #include <aesbind.h>
- #ifdef NEW_SCREEN
- #include <linea.h>
- #endif
- #include <vdibind.h>
- #include <osbind.h>
- #include <mintbind.h>
-
-
- /*
- * globals...
- */
- long _stksize = 16*1024L; /* do we need this much? */
-
- char *uniterm_cmd =
- "E:\\LOCAL\\UNI20E\\UNITERM\\UNITERM.PRG\0 ";
- /* default command if no args */
- /* plenty of patch space... */
- int debugging = 0;
- int nogo = 0;
-
- char cmd[512];
- char tail[512];
- #ifdef NEW_SCREEN
- char *altscreen; /* address of new screen */
- char *alloc_mem;
- char *phys, *log;
- #endif
- int ap_id;
- int screen_phandle;
- int screen_vhandle;
- int gr_wchar, gr_hchar, gr_wbox, gr_hbox;
- int old_domain;
- char *myname;
-
-
- /*
- * local functions...
- */
- char *prg_name ();
- int open_vwork ();
- void clr_screen ();
- int run_prog ();
- void quit ();
- void usage ();
- #ifdef NEW_SCREEN
- char *newscreen ();
- #endif
-
-
-
- /*------------------------------*/
- /* main */
- /*------------------------------*/
- void main (int argc, char *argv[])
- {
- int excode;
-
-
- /*
- * find our name. strip of any path
- */
- #ifdef __GNUC__
- myname = prg_name (argv[0]);
- #else
- myname = "rg";
- #endif
-
-
- /*
- * parse args. if none, use default (uniterm)
- *
- * first look for - or + options...
- */
- for (argc--, argv++; (argc && ((**argv == '-') || (**argv == '+')));
- argc--, argv++)
- {
- if (**argv == '+')
- {
- switch (*(*argv+1))
- {
- case 'v': /* +version */
- fprintf (stderr, "%s\n", rcsid);
- exit (0);
- break; /*NOTREACHED*/
-
- case 'h': /* +help */
- usage ();
- break; /*NOTREACHED*/
-
- case 'd': /* +debug */
- debugging++;
- break;
-
- case 'n': /* +nogo */
- nogo++;
- debugging++;
- break;
- }
- }
- else
- {
- switch (*(*argv+1))
- {
- case 'v': /* -v, version */
- fprintf (stderr, "%s\n", rcsid);
- exit (0);
- break; /*NOTREACHED*/
-
- case 'h': /* -h, help */
- usage ();
- break; /*NOTREACHED*/
-
- case 'd': /* -d, debug */
- debugging++;
- break;
-
- case 'n': /* -n, nogo */
- nogo++;
- debugging++;
- break;
- }
- }
- }
-
-
- /*
- * any remaining args are command and (optional) tail. if no
- * more args, use default command and tail (uniterm)...
- */
- if (argc > 0)
- {
- strcpy (cmd, *argv);
- for (argc--, argv++; (argc && *argv); argc--, argv++)
- {
- strcat (tail, *argv);
- if (argc > 1)
- strcat (tail, " ");
- }
- }
- else
- {
- strcpy (cmd, uniterm_cmd);
- tail[0] = 0;
- }
- if (debugging)
- {
- fprintf (stderr, "%s: running:\t\"%s\"\n", myname, cmd);
- fprintf (stderr, "%s: tail:\t\"%s\"\n", myname, tail);
- if (!nogo)
- sleep ((unsigned int) 2);
- }
- if (nogo)
- {
- exit (0);
- }
-
-
-
- /*
- * The desktop is a TOS domain program, but the MiNT library sets up
- * MiNT domain by default, so we'd better change it back. save the
- * current domain for later reset...
- */
- old_domain = Pdomain (-1);
- (void) Pdomain (0);
-
-
- #ifdef NEW_SCREEN
- /*
- * allocate memory for new screen...
- */
- if ((altscreen = newscreen()) == NULL)
- {
- fprintf (stderr, "%s: could allocate memory for screen\n", myname);
- quit (0, 1);
- }
- #endif
-
-
- /*
- * application init...
- */
- if ((ap_id = appl_init ()) < 0)
- {
- fprintf (stderr, "%s: could not do appl_init\n", myname);
- quit (1, 2);
- }
-
-
- /*
- * get handle for screen...
- */
- screen_phandle = graf_handle (&gr_wchar, &gr_hchar, &gr_wbox, &gr_hbox);
-
-
- /*
- * open virtual workstation and clear it...
- */
- if ((screen_vhandle = open_vwork (screen_phandle)) == 0)
- {
- quit (2, 3);
- }
- v_clrwk (screen_vhandle);
-
-
- /*
- * hide cursor, show mouse...
- */
- Cconws ("\033f"); /* cursor off */
- v_show_c (screen_vhandle, 0); /* mouse on */
-
-
- #ifdef NEW_SCREEN
- /*
- * save screen, set to altscreen...
- */
- log = (char *) Logbase ();
- phys = (char *) Physbase ();
- Setscreen (altscreen, altscreen, -1);
- #endif
-
-
- /*
- * do it...
- */
- excode = run_prog (cmd, tail);
-
-
- #ifdef NEW_SCREEN
- /*
- * reset screen...
- */
- Setscreen (log, phys, -1);
- #endif
-
-
- /*
- * show cursor, hide mouse...
- */
- v_hide_c (screen_vhandle); /* mouse cursor off */
- Cconws ("\033e"); /* cursor on */
-
-
- /*
- * exit with status of command...
- */
- quit (10, excode);
- }
-
-
-
- /*------------------------------*/
- /* quit */
- /*------------------------------*/
- void quit (int opt, int excode)
- {
- switch (opt)
- {
- case 10: /* normal exit */
- case 4:
- /* */
- /* FALLTHRU */
-
- case 3:
- v_clrwk (screen_vhandle); /* clear screen */
- v_clsvwk (screen_vhandle); /* close vwork */
- /* FALLTHRU */
-
- case 2: /* open_vwork failed... */
- appl_exit (); /* exit appl */
- /* FALLTHRU */
-
- case 1: /* appl_init failed ... */
- #ifdef NEW_SCREEN
- Mfree (alloc_mem); /* free screen memory */
- #endif
- /* FALLTHRU */
-
- case 0: /* newscreen failed... */
- (void) Pdomain (old_domain); /* reset domain */
- clr_screen (); /* clear screen */
- exit (excode); /* exit code */
- break; /* NOTREACHED */
- }
- }
-
-
-
- /*------------------------------*/
- /* open_vwork */
- /*------------------------------*/
- int open_vwork (int phandle)
- {
- int work_in[12];
- int work_out[60];
- int new_handle;
- int i;
-
- for (i = 0; i < 10; i++)
- work_in[i] = 1;
- work_in[10] = 2;
- new_handle = phandle;
-
- v_opnvwk (work_in, &new_handle, work_out);
-
- return (new_handle);
- }
-
-
-
- /*------------------------------*/
- /* clr_screen */
- /*------------------------------*/
- void clr_screen (void)
- {
- Cconws ("\33E"); /* clear screen via GEMDOS */
- }
-
-
-
- /*------------------------------*/
- /* run_prog */
- /*------------------------------*/
- int run_prog (char *rcmd, char *rtail)
- {
- long ret;
-
- ret = Pexec ((short) 0, (long) rcmd, (long) rtail, (long) 0);
-
- return ((int) ret);
- }
-
-
-
- #ifdef NEW_SCREEN
- /*------------------------------*/
- /* newscreen */
- /*------------------------------*/
- char *newscreen (void)
- {
- long temp;
- long size;
- char *foo, *ret;
-
- linea0 ();
- size = __aline->_VWRAP * V_Y_MAX;
-
- temp = Malloc (size + 512);
- if (!temp)
- return ((char *) 0);
-
- alloc_mem = (char *) temp;
- foo = ret = (char *) ((temp + 511) & ~511);
-
- while (size-- > 0) /* clear the screen */
- *foo++ = 0;
-
- return ((char *) ret);
- }
- #endif /*NEW_SCREEN*/
-
-
-
- /*------------------------------*/
- /* prg_name */
- /*------------------------------*/
- char *prg_name (char *av)
- {
- /*
- * MiNT can include full path in argv[0]. this finds just the name.
- */
- char *ps1;
- char *ps2;
-
- ps1 = rindex (av, '/');
- ps2 = rindex (av, '\\');
- if ((long) ps1 > 0 && (long) ps1 > (long) ps2)
- return (++ps1);
- else if ((long) ps2 > 0 && (long) ps2 > (long) ps1)
- return (++ps2);
- else
- return (av);
- }
-
-
-
- /*------------------------------*/
- /* usage */
- /*------------------------------*/
- void usage ()
- {
- fprintf (stderr, "usage: %s [-n][-d][-h][-v] gem_program [tail]\n", myname);
- fprintf (stderr, " %s [+nogo][+version][+debug][+help] ...\n", myname);
- exit (0);
- }
-
-